import com.alicloud.openservices.tablestore.AsyncClient;
import com.alicloud.openservices.tablestore.AsyncClientInterface;
import com.alicloud.openservices.tablestore.TableStoreCallback;
import com.alicloud.openservices.tablestore.SyncClient;
import com.alicloud.openservices.tablestore.model.ColumnValue;
import com.alicloud.openservices.tablestore.model.Request;
import com.alicloud.openservices.tablestore.model.Response;
import com.alicloud.openservices.tablestore.model.search.SearchQuery;
import com.alicloud.openservices.tablestore.model.search.SearchRequest;
import com.alicloud.openservices.tablestore.model.search.SearchResponse;
import com.alicloud.openservices.tablestore.model.search.query.TermQuery;
import example.grid.common.ExampleConfig;
import example.grid.common.TableStoreGridExample;

import java.util.concurrent.Future;

class Serach extends TableStoreGridExample {
    AsyncClientInterface client;
    SyncClient syncClient;
    Serach(){
        super(ExampleConfig.GRID_DATA_TABLE_NAME, ExampleConfig.GRID_META_TABLE_NAME);
        this.client =  this.tableStoreGrid.asyncClient;
        syncClient = new SyncClient(config.getTableStoreEndpoint(), config.getAccessId(), config.getAccessKey(), config.getTableStoreInstance());

    }
    public SearchResponse termQuery(){
        SearchQuery searchQuery = new SearchQuery();
        TermQuery termQuery = new TermQuery();
        termQuery.setFieldName("status");
        termQuery.setTerm(ColumnValue.fromString("DONE"));
        searchQuery.setQuery(termQuery);
        searchQuery.setGetTotalCount(true);
        SearchRequest searchRequest = new SearchRequest(ExampleConfig.GRID_META_TABLE_NAME, ExampleConfig.GRID_META_INDEX_NAME, searchQuery);
        SearchResponse search = this.syncClient.search(searchRequest);
        System.out.println("TotalCount: " + search.getTotalCount());
        System.out.println(search.getRows());
        return null;
    }
    public void close(){
        this.syncClient.shutdown();
    }
}

class MyTableStoreCallback implements TableStoreCallback<SearchRequest, SearchResponse>{


    @Override
    public void onCompleted(SearchRequest request, SearchResponse response) {
        System.out.println("sdfds");
    }

    @Override
    public void onFailed(SearchRequest request, Exception e) {

    }
}

public class MyStore {
    public static void main(String[] args) {
        Serach serach = new Serach();
        try{
            serach.termQuery();
        }
        finally{
            serach.close();
        }
    }
}
